package com.edu.comment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.api.entity.commentdto.CourseCommentDto;
import com.edu.api.entity.common.Pageable;
import com.edu.api.entity.common.ResponseDTO;
import com.edu.comment.service.CourseCommentService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @description: 描述
 * @author: xnylh
 * @createDate: 2023/1/9 0009 14:47
 */
@RestController
@RequestMapping("comment")
public class CourseCommentController {

    @Autowired
    CourseCommentService courseCommentService;

    /**
     * 查询课程评论
     * @return
     */
    @GetMapping("/getCourseCommentList/{id}/{page}/{size}")
    public ResponseDTO getCourseCommentList(@PathVariable("id")String id, @PathVariable("page")Integer page, @PathVariable("size") Integer size){
        Pageable pageable = new Pageable();
        pageable.setPage(page);
        pageable.setSize(size);
        return courseCommentService.getCourseCommentList(id,pageable);
    }

    @GetMapping("/saveOrCancelFavorite/{commentId}")
    public ResponseDTO saveOrCancelFavorite(@PathVariable Integer commentId, HttpServletRequest request){
        return courseCommentService.saveOrCancelFavorite(commentId,request);
    }

    @GetMapping("/saveCourseComment")
    public ResponseDTO<Integer> getCourseCommentList(@Param("courseId") String courseId, @Param("userId") String userId, @Param("userName") String userName, @Param("comment") String comment){
        return courseCommentService.saveCourseComment(courseId,userId,userName,comment);
    }
}
